<template>
  <basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               ref="crud"
               v-model="form"
               :defaults.sync="showColumn"
               :permission="permissionList"
               :page.sync="page"
               :before-open="beforeOpen"
               @sortable-change="sortableChange"
               @row-del="rowDel"
               @row-update="rowUpdate"
               @row-save="rowSave"
               @refresh-change="refreshChange"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @filter="filterChange"
               @sort-change="sortChange"
               @row-dblclick="handleRowDBLClick"               
               @on-load="onLoad">
      <template slot-scope="scope" slot="menu">
        <el-button type="text"
                   size="small"
                   icon="el-icon-s-operation"
                   v-if="permission.biz_apparch_demand_edit"
                   @click="splitSceneList(scope.row)">拆分场景
        </el-button>
      </template>
      <template slot-scope="scope" slot="menuForm">
        <div  style="text-align:right; float:right">
          <el-button type="text" v-if="operateType == 'edit'"  icon="el-icon-time" style="font-weight:normal;" size="large" @click.stop="getHistoryRecord">修改历史</el-button>
        </div> 
      </template>
      <template slot-scope="scope" slot="demandFileAddressForm">
        <file-selector
              :fileList="form.demandFileAddress"
              :openType="openType"
              :multiple="true"
              @changeFileList='changeFileList'
            >
        </file-selector>
      </template>
      <template slot-scope="scope" slot="menuLeft">
        <el-button type="primary"
                   size="small"
                   icon="el-icon-plus"
                   v-if="permission.biz_apparch_demand_batch_add"
                   @click.stop="openBatchAddDialog">批量新增
        </el-button>
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   v-if="permission.biz_apparch_demand_batch_delete"
                   @click.stop="handleDelete">删 除
        </el-button>
      </template>
      <template slot="menuRight">
        <el-button v-if="permission.biz_apparch_demand_download" type="default" @click.stop="exportExcel"  title="下载" icon="el-icon-download" circle size="small"></el-button>
      </template>
    </avue-crud>
    <!-- 
      拆分场景对话框
     -->
    <el-dialog :title="sceneDialogTitle" width='100%' :fullscreen='true'   :visible.sync="sceneListDialog">
      <biz-apparch-scene-list
      :demandData='currentRow'
      >
      </biz-apparch-scene-list>
      <div slot="title">
        <span class="titleName">场景拆分</span>
        
        <span class="titleAltBoldName">需求编号：</span> 
        <span class="titleAltName">{{sceneDialogTitleNo}}</span> 

        <span class="titleAltBoldName">需求名称：</span> 
        <span class="titleAltName">{{sceneDialogTitle}}</span> 

      </div>
    </el-dialog>
    <!-- 
      批量添加数据对话框
     -->
    <el-dialog title="批量导入" width='80%' :close-on-click-modal='false' :visible.sync="batchAddDialog">
      <el-tag>
		项目ID，
		项目名称，
		需求名称，
		需求来源，
		需求类别，
		需求文档地址，
		需求描述，
		优先级，
		主责部门，
		协办部门，
		需求提出人，
		需求提出人名，
		需求提出日期，
		需求受理人，
		需求受理人名，
		需求受理日期
      </el-tag>
      <el-input
        type="textarea"
        :autosize="{ minRows: 10, maxRows: 20}"
        placeholder="请直接从excel粘贴内容"
        v-model="importDataArea">
      </el-input>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" id="copyBtn" @click="handleImport($event)" data-clipboard-target="#pathText">开始导入</el-button>
        <el-button size="small" @click="batchAddDialog = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 历史记录 -->
    <update-history ref="historyRecord"></update-history>
  </basic-container>
</template>

<script>
import {exportBizApparchDemandExcel,saveOrUpdateBizApparchDemand,saveOrUpdateBizApparchDemandList,saveBizApparchDemand,saveBizApparchDemandList,deleteBizApparchDemand,queryBizApparchDemand,queryBizApparchDemandListPage,updateBizApparchDemand,deleteBizApparchDemandList} from '@/api/biz/apparch/bizApparchDemandApi';
import {mapGetters} from 'vuex';
import { reqCommonMsg } from '@/util/reqCommonMsg';
import {filterFormat} from '@/util/util';
import BizApparchSceneList from './bizApparchSceneList.vue';
export default {
  components:{
    BizApparchSceneList
  },
  data() {
    return {
      //业务拆分场景对话框
      sceneListDialog: false,
      sceneDialogTitle: '拆分场景',
      sceneDialogTitleNo: '',
      //文件选择器的打开方式 add新增、edit修改、view 查看
      openType: 'edit',
      
      // 当前打开form对话框操作类型 
      operateType: 'add',
      
      //修改记录对话框
      historyDialog: false,
      //如果做流程表单 请将次开关设置为true，否则设置为false
      isFlow: true,
      flowArea: {},
      
      importDataArea: '',
      batchAddDialog: false,
      form: {},
      currentRow: {},
      selectionList: [],
      loading: true, 
      showColumn: [],
      option: {
        labelPosition: 'right',
        labelSuffix: '：',
        labelWidth: 120,
        dialogTop: '50',
        indexFixed:true, 
        stripe:true,
        calcHeight: 80,
        searchShow: true,
        searchMenuSpan: 6,
        tip: false,
        border: true,
        index: true,
        selection: true,
        addBtn: true,
        viewBtn: false,
        delBtn: false,
        cancelBtn: true,
        printBtn:false,
        saveBtn: true,
        filterBtn:true,          
        menuWidth: 200,
        dialogMenuPosition: 'center',
        dialogDirection:'rtl',
        dialogType:'dialog',
        dialogFullscreen:false,
        dialogClickModal:false,
        dialogWidth: '70%',
        highlightCurrentRow:  true,
        searchShow:true,
        sortable: true,
        column: [
          {
            label: '需求编号',
            prop: 'id', 
            type: 'input', 
            search: true,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: false,
            width:180,
            maxlength: 30,
            overHidden: true,
            display:false,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 30,
              message: '内容长度不能超过30字符',
              trigger: 'blur'
            }],
            dicData:[]
          },
          {
            label: '需求名称',
            prop: 'demandName', 
            type: 'input', 
            search: true,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: false,
            maxlength: 50,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  true,
              trigger: 'blur'
            },
            {
              max: 50,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[]
          },
          {
            label: '需求来源',
            prop: 'demandSource', 
            type: 'select', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: false,
            maxlength: 100,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  true,
              trigger: 'blur'
            },
            {
              max: 100,
              message: '内容长度不能超过100字符',
              trigger: 'blur'
            }],
            dicData:[]
          },
          {
            label: '需求类别',
            prop: 'demandCategory', 
            type: 'select', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: false,
            maxlength: 30,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  true,
              trigger: 'blur'
            },
            {
              max: 30,
              message: '内容长度不能超过30字符',
              trigger: 'blur'
            }],
            dicData:[]
          },
          {
            label: '优先级',
            prop: 'priorLevel', 
            type: 'select', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: false,
            maxlength: 30,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  true,
              trigger: 'blur'
            },
            {
              max: 30,
              message: '内容长度不能超过30字符',
              trigger: 'blur'
            }],
            dicData:[]
          },
          {
            label: '需求文档',
            prop: 'demandFileAddress', 
            type: 'input', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 24,
            sortable: false,
            hide: true,
            formslot:true,
            overHidden: true,
            showColumn: false,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            }],
            dicData:[]
          },
          {
            label: '需求描述',
            prop: 'demandDesc', 
            type: 'textarea', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 24,
            sortable: false,
            hide: true,
            maxlength: 2000,
            overHidden: true,
            maxRows:5,
            minRows:5,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 2000,
              message: '内容长度不能超过2000字符',
              trigger: 'blur'
            }],
            dicData:[]
          },
          
          {
            label: '主责部门',
            prop: 'masterDeptName', 
            type: 'tree', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 30,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 30,
              message: '内容长度不能超过30字符',
              trigger: 'blur'
            }],
            props: {
              label: 'orgName',
              value: 'orgName'
            },
            dicData:[]
          },
          {
            label: '协办部门',
            prop: 'assistDeptName', 
            type: 'tree', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 30,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 30,
              message: '内容长度不能超过30字符',
              trigger: 'blur'
            }],
            props: {
              label: 'orgName',
              value: 'orgName'
            },
            dicData:[]
          },
          {
            label: '需求提出人',
            prop: 'demandProposeUserName', 
            type: 'select',
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 50,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 50,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[],
            remote: true,
            dicMethod:'get',
            dicUrl: '/platform/sysUserInfo/querySysUserInfoListPage?optFlag=org&columnValue={{key}}&columnName=realName&tenantId='+localStorage.getItem('tenantId'),
            props: {
              label: 'userName',
              value: 'realName'
            },
          },
          {
            label: '需求提出日期',
            prop: 'demandProposeDate', 
            type: 'date', 
            format:'yyyy-MM-dd',
            valueFormat: 'yyyy-MM-dd',
            pickerOptions: {
              disabledDate(time) {
                return time.getTime() + 3600 * 1000 * 24 <= Date.now();
              }
            },
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 20,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 20,
              message: '内容长度不能超过20字符',
              trigger: 'blur'
            }],
            dicData:[]
          },
          {
            label: '需求受理人',
            prop: 'demandAcceptUserName', 
            type: 'select', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 50,
            overHidden: true,
            addDisplay:false,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 50,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[],
            remote: true,
            dicMethod:'get',
            dicUrl: '/platform/sysUserInfo/querySysUserInfoListPage?optFlag=org&columnValue={{key}}&columnName=realName&tenantId='+localStorage.getItem('tenantId'),
            props: {
              label: 'userName',
              value: 'realName'
            },
          },
          {
            label: '需求受理日期',
            prop: 'demandAcceptDate', 
            type: 'date', 
            format:'yyyy-MM-dd',
            valueFormat: 'yyyy-MM-dd',
            pickerOptions: {
              disabledDate(time) {
                return time.getTime() + 3600 * 1000 * 24 <= Date.now();
              }
            },
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 20,
            overHidden: true,
            addDisplay:false,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 20,
              message: '内容长度不能超过20字符',
              trigger: 'blur'
            }],
            dicData:[]
          },
          
          {
            label: '业务分析人',
            prop: 'bizAnalyseUserName', 
            type: 'select', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 50,
            overHidden: true,
            addDisplay:false,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 50,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[],
            remote: true,
            dicMethod:'get',
            dicUrl: '/platform/sysUserInfo/querySysUserInfoListPage?optFlag=org&columnValue={{key}}&columnName=realName&tenantId='+localStorage.getItem('tenantId'),
            props: {
              label: 'userName',
              value: 'realName'
            },
          },
          {
            label: '计划上线日期',
            prop: 'planOnlineDate', 
            type: 'date', 
            format:'yyyy-MM-dd',
            valueFormat: 'yyyy-MM-dd',
            pickerOptions: {
              disabledDate(time) {
                return time.getTime() + 3600 * 1000 * 24 <= Date.now();
              }
            },
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 20,
            overHidden: true,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 20,
              message: '内容长度不能超过20字符',
              trigger: 'blur'
            }],
            dicData:[]
          }, 
          {
            label: '系统分析人',
            prop: 'systemAnalyseUserName', 
            type: 'select', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 50,
            overHidden: true,
            addDisplay:false,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 50,
              message: '内容长度不能超过50字符',
              trigger: 'blur'
            }],
            dicData:[],
            remote: true,
            dicMethod:'get',
            dicUrl: '/platform/sysUserInfo/querySysUserInfoListPage?optFlag=org&columnValue={{key}}&columnName=realName&tenantId='+localStorage.getItem('tenantId'),
            props: {
              label: 'userName',
              value: 'realName'
            },
          },
          {
            label: '实际上线日期',
            prop: 'actualOnlineDate', 
            type: 'date', 
            format:'yyyy-MM-dd',
            valueFormat: 'yyyy-MM-dd',
            pickerOptions: {
              disabledDate(time) {
                return time.getTime() + 3600 * 1000 * 24 <= Date.now();
              }
            },
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 20,
            overHidden: true,
            addDisplay:false,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 20,
              message: '内容长度不能超过20字符',
              trigger: 'blur'
            }],
            dicData:[]
          },
          {
            label: '评审状态',
            prop: 'reviewStatus', 
            type: 'select', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 30,
            overHidden: true,
            addDisplay:false,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 30,
              message: '内容长度不能超过30字符',
              trigger: 'blur'
            }],
            dicData:[]
          },
          {
            label: '评审通过日期',
            prop: 'reviewPassDate', 
            type: 'date', 
            format:'yyyy-MM-dd',
            valueFormat: 'yyyy-MM-dd',
            pickerOptions: {
              disabledDate(time) {
                return time.getTime() + 3600 * 1000 * 24 <= Date.now();
              }
            },
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 20,
            overHidden: true,
            addDisplay:false,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 20,
              message: '内容长度不能超过20字符',
              trigger: 'blur'
            }],
            dicData:[]
          },
          {
            label: '当前版本号',
            prop: 'newVersionNo', 
            type: 'input', 
            search: true,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 30,
            overHidden: true,
            width: 110,
            value: this.$toolUtil.formatDateToYyyyMmDd(new Date()),
            rules: [{
              message: '请输入内容',
              required:  true,
              trigger: 'blur'
            },
            {
              max: 30,
              message: '内容长度不能超过30字符',
              trigger: 'blur'
            }],
            dicData:[]
          },
          
          {
            label: '需求状态',
            prop: 'demandStatus', 
            type: 'select', 
            search: false,
            searchMmultiple: false,
            searchLabelWidth: 100,
            multiple: false,
            span: 12,
            sortable: false,
            hide: true,
            maxlength: 30,
            overHidden: true,
            addDisplay:false,
            rules: [{
              message: '请输入内容',
              required:  false,
              trigger: 'blur'
            },
            {
              max: 30,
              message: '内容长度不能超过30字符',
              trigger: 'blur'
            }],
            dicData:[]
          },
          {
            label: '标签信息',
            prop: 'labelInfo', 
            type: 'dynamic', 
            span: 24,
            hide: true,
            children: {
              align: 'center',
              headerAlign: 'center', 
              column: [
                {
                  label: '标签类型',
                  prop: 'labelType',
                  type: 'select',
                  width: 120,
                  rules:[{
                    required:  true,
                    message: '请输入内容',
                  }],
                  dicData: [{
                    label: '测试',
                    value: '测试'
                  }, 
                  {
                    label: '通用',
                    value: '通用'
                  }]
                },
                {
                  label: '标签值',
                  prop: 'labelValues',
                  type: 'select',
                  multiple: true,
                  filterable: true,
                  rules: [{
                    type: 'array',
                    required: true,
                    message: '请输入内容',
                  }],
                  dicData:[],
                }, 
              ]
            }
          },
        ]
      },
      data: [],
      // 请求参数区
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      reqParams: {
        singleBody: {},
        listBody: [{}],
        sqlCondition:[],
        orderRule: [],
        currentPage: 1,
        pageSize: 10
      },
      commonData: null,
      conditions: [],
      orderRules: [],
      singleBody: {}
    };
  },
  computed: {
    ...mapGetters(['website','orgTree','genOrgTree','userInfo','permission','projectInfo']),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.biz_apparch_demand_add, false),
        viewBtn: this.vaildData(this.permission.biz_apparch_demand_view, false),
        delBtn: this.vaildData(this.permission.biz_apparch_demand_delete, false),
        editBtn: this.vaildData(this.permission.biz_apparch_demand_edit, false),
        printBtn: this.vaildData(this.permission.biz_apparch_demand_print, false),
        searchBtn:this.vaildData(this.permission.biz_apparch_demand_search, false)
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach(ele => {
        ids.push({id : ele.id});
      });
      return ids;
    } 
  },
  methods: {
    /**
     * 打开拆分场景对话框
     */
    splitSceneList(row){
      this.sceneListDialog = true;
      this.currentRow = row;
      this.sceneDialogTitle = row.demandName;
      this.sceneDialogTitleNo = row.id
    },
    
    /**
     * 选择文件后由子组件触发修改fileList
     */
    changeFileList(fileList){
      this.form.demandFileAddress = JSON.parse(JSON.stringify(fileList));
      //this.$console.log('demandFileAddress==', this.form.demandFileAddress);
    },
    
    /**
     * 加载列表数据
     */
    onLoad(page) {
   	   
      //this.singleBody.projectId = this.projectInfo.id;
      this.loading = true;
      this.reqParams =  {
        singleBody: this.singleBody,
        listBody: [{}],
        sqlCondition: this.conditions,
        orderRule: this.orderRules,
        currentPage: page.currentPage, 
        pageSize: page.pageSize
      }
      this.commonData = reqCommonMsg(this.reqParams)
      queryBizApparchDemandListPage(this.commonData).then(res => {
        const data = res.data.body;
        this.page.total = data.total;
        this.data = data.listBody;
        this.loading = false;
        this.selectionClear();
      }, error => {
        this.loading = false; 
      });
    },
    /**
     * 新增一条记录
     */
    rowSave(row, done, loading) {
      row.versionNo = row.newVersionNo;
      this.reqParams.singleBody = row;
      let formatUser = {};
      // 解析用户名（用户ID）
      formatUser = this.$util.formatUserName(row.demandProposeUserName);
      this.reqParams.singleBody.demandProposeUserName = formatUser.userId; 
      this.reqParams.singleBody.demandProposeRealName = formatUser.userName;
      // 解析用户名（用户ID）
      formatUser = this.$util.formatUserName(row.demandAcceptUserName);
      this.reqParams.singleBody.demandAcceptUserName = formatUser.userId; 
      this.reqParams.singleBody.demandAcceptRealName = formatUser.userName;
      // 解析用户名（用户ID）
      formatUser = this.$util.formatUserName(row.bizAnalyseUserName);
      this.reqParams.singleBody.bizAnalyseUserName = formatUser.userId; 
      this.reqParams.singleBody.bizAnalyseRealName = formatUser.userName;
      // 解析用户名（用户ID）
      formatUser = this.$util.formatUserName(row.systemAnalyseUserName);
      this.reqParams.singleBody.systemAnalyseUserName = formatUser.userId; 
      this.reqParams.singleBody.systemAnalyseRealName = formatUser.userName;
      this.commonData = reqCommonMsg(this.reqParams)
      if(this.reqParams.singleBody.demandFileAddress == ''){
        this.reqParams.singleBody.demandFileAddress =  '[]';
      }
      else{
        this.reqParams.singleBody.demandFileAddress =  JSON.stringify(row.demandFileAddress);
      }
      saveBizApparchDemand(this.commonData).then(() => {
        done();
        this.singleBody={};
        this.onLoad(this.page);
        this.$message({
          type: 'success',
          message: '操作成功!'
        });
      }, error => {
        //this.$console.log(error);
        done();
      });         
      //this.$console.log("row = ",row ,loading)
    },
    /**
     * 修改一条记录
     */
    rowUpdate(row, index, done, loading) {
      this.reqParams.singleBody = row;
      let formatUser = {};
      // 解析用户名（用户ID）
      formatUser = this.$util.formatUserName(row.demandProposeUserName);
      this.reqParams.singleBody.demandProposeUserName = formatUser.userId; 
      this.reqParams.singleBody.demandProposeRealName = formatUser.userName;
      // 解析用户名（用户ID）
      formatUser = this.$util.formatUserName(row.demandAcceptUserName);
      this.reqParams.singleBody.demandAcceptUserName = formatUser.userId; 
      this.reqParams.singleBody.demandAcceptRealName = formatUser.userName;
      // 解析用户名（用户ID）
      formatUser = this.$util.formatUserName(row.bizAnalyseUserName);
      this.reqParams.singleBody.bizAnalyseUserName = formatUser.userId; 
      this.reqParams.singleBody.bizAnalyseRealName = formatUser.userName;
      // 解析用户名（用户ID）
      formatUser = this.$util.formatUserName(row.systemAnalyseUserName);
      this.reqParams.singleBody.systemAnalyseUserName = formatUser.userId; 
      this.reqParams.singleBody.systemAnalyseRealName = formatUser.userName;
      this.commonData = reqCommonMsg(this.reqParams)
      if(this.reqParams.singleBody.demandFileAddress == ''){
        this.reqParams.singleBody.demandFileAddress =  '[]';
      }
      else{
        this.reqParams.singleBody.demandFileAddress =  JSON.stringify(row.demandFileAddress);
      }
      updateBizApparchDemand(this.commonData).then(() => {
        done();
        this.singleBody={}
        this.onLoad(this.page);
        this.$message({
          type: 'success',
          message: '操作成功!'
        });
      }, error => {
        //this.$console.log(error);
        done();
      });
    },
    /**
     * 删除一条记录
     */
    rowDel(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.reqParams.singleBody = row;
          this.commonData = reqCommonMsg(this.reqParams);
          return deleteBizApparchDemand(this.commonData);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
        }).catch(() => {});
    },
    /**
     * 双击打开详细窗口
     */
    handleRowDBLClick (row, event) {
      if(this.permission.biz_apparch_demand_dbclick){
        this.$refs.crud.rowView(row,row.$index);
      }
    },
    /**
     * 批量新增记录
     */
    openBatchAddDialog(){
      this.batchAddDialog = true;
    },
    /**
     * 批量导入
     */
    handleImport() {
      const loading = this.$loading({
        lock: true,
        text: '处理中...',
        spinner: 'el-icon-loading',
      });
      var dataList = new Array();
      if(this.importDataArea){
        var lineList = this.importDataArea.split('\n')
        lineList.forEach((element,index) => {
          if(element.trim() != ''){
            var field = element.split('\t')
            var fieldList = {
              projectId:field[0].trim(),
              projectName:field[1].trim(),
              demandName:field[2].trim(),
              demandSource:field[3].trim(),
              demandCategory:field[4].trim(),
              demandFileAddress:field[5].trim(),
              demandDesc:field[6].trim(),
              priorLevel:field[7].trim(),
              masterDeptName:field[8].trim(),
              assistDeptName:field[9].trim(),
              demandProposeUserName:field[10].trim(),
              demandProposeRealName:field[11].trim(),
              demandProposeDate:field[12].trim(),
              demandAcceptUserName:field[13].trim(),
              demandAcceptRealName:field[14].trim(),
              demandAcceptDate:field[15].trim(),
              reviewNo:field[16].trim(),
              reviewStatus:field[17].trim(),
              reviewPassDate:field[18].trim(),
              windowNo:field[19].trim(),
              planOnlineDate:field[20].trim(),
              actualOnlineDate:field[21].trim(),
              bizAnalyseUserName:field[22].trim(),
              bizAnalyseRealName:field[23].trim(),
              systemAnalyseUserName:field[24].trim(),
              systemAnalyseRealName:field[25].trim(),
              versionNo:field[26].trim(),
              changeDate:field[27].trim(),
              demandStatus:field[28].trim(),
            }
            dataList[index] = fieldList
            //this.$console.log('fieldList = ',fieldList)
          }
        });
        //批量写入记录
        this.reqParams.listBody = dataList;
        this.commonData = reqCommonMsg(this.reqParams)
        saveBizApparchDemandList(this.commonData).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
          loading.close();
        }, error => {
          //this.$console.log(error);
          loading.close();
        });      
      }
      else{
        this.loading=false;
        this.$message({
          type: 'warning',
          message: '数据格式不正确!'
        });
      }
    },
    /**
     * 搜索重置
     */
    searchReset() {
      this.conditions =[];
      this.singleBody = {};
      this.onLoad(this.page);
    },
    /**
     * 搜索
     */
    searchChange(params, done) {
      this.singleBody = params
      this.page.currentPage = 1;
      this.onLoad(this.page);
      done();
    },
    refreshChange(){
      this.onLoad(this.page);
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    /**
     * 处理批量删除
     */
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.reqParams.listBody = this.ids;
          this.commonData = reqCommonMsg(this.reqParams);
          return deleteBizApparchDemandList(this.commonData);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
          this.$refs.crud.toggleSelection();
        }).catch(() => {});
    },
    /**
     * 拷贝记录
     */
    handleCopy(row){
      this.$confirm('确定复制数据?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading=true;
        let copyValue=row;
        copyValue.id='0';
        copyValue.dataSign='0'
        copyValue.tableName='拷贝 '+ copyValue.tableName; 
        this.reqParams.singleBody = copyValue;
        this.commonData = reqCommonMsg(this.reqParams)
        saveSysToolTables(this.commonData).then(() => {
          this.singleBody={};
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
          this.loading=false;
        }, error => {
          //this.$console.log(error);
          this.loading=false;
        });
      }).catch(() => {});       
    },
    /**
     * 打开编辑、查询弹窗前查询记录
     */  
    beforeOpen(done, type) {
      this.openType = type;
      if (['edit', 'view'].includes(type)) {
        this.operateType = 'edit';        
        this.reqParams =  {
          singleBody: {
            id:this.form.id
          }
        }
        let commonData = reqCommonMsg(this.reqParams)
        const loading = this.$loading({
          lock: true,
          text: 'Loading',
          spinner: 'el-icon-loading'
        });
        queryBizApparchDemand(commonData).then(res => {
          this.form = res.data.body.singleBody;
          if(this.form.demandFileAddress.indexOf('[') > -1 && this.form.demandFileAddress.indexOf(']') > -1){
            this.form.demandFileAddress  = JSON.parse(this.form.demandFileAddress);
          }
          if(res.data.body.singleBody.demandProposeUserName){
            this.form.demandProposeUserName = res.data.body.singleBody.demandProposeRealName+'('+ res.data.body.singleBody.demandProposeUserName +')';
          }
          if(res.data.body.singleBody.demandAcceptUserName){
            this.form.demandAcceptUserName = res.data.body.singleBody.demandAcceptRealName+'('+ res.data.body.singleBody.demandAcceptUserName +')';
          }
          if(res.data.body.singleBody.bizAnalyseUserName){
            this.form.bizAnalyseUserName = res.data.body.singleBody.bizAnalyseRealName+'('+ res.data.body.singleBody.bizAnalyseUserName +')';
          }
          if(res.data.body.singleBody.systemAnalyseUserName){
            this.form.systemAnalyseUserName = res.data.body.singleBody.systemAnalyseRealName+'('+ res.data.body.singleBody.systemAnalyseUserName +')';
          }
          this.form.labelInfo = JSON.parse(this.form.labelInfo);
          loading.close();
          done();
        }, error => {
          //this.$console.log(error);
          loading.close();
          done();
        });
      }
      if (['add'].includes(type)) {
        this.operateType = 'add';   
        setTimeout(() => {
          this.form = {};
        }, 100);     
        done();
      }
    },
    /**
     * 翻页查询
     */
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    /**
     * 更改每页条数
     */
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    /**
     * 自定义查询条件
     */
    filterChange(result) {
      this.page.currentPage = 1;
      this.conditions = filterFormat(result)
      this.onLoad(this.page);
    },
    /**
     * 列表排序
     */
    sortChange(val){
      this.orderRules=val
      this.onLoad(this.page);
    },
  
    /**
     * 导出Excel
     */
    exportExcel() {
      this.reqParams =  {
        singleBody: this.singleBody,
        listBody: [{}],
        sqlCondition: this.conditions,
        orderRule: this.orderRules,
        currentPage:1, 
        pageSize: 100
      }
      //this.$console.log('reqParams = ',this.reqParams)
      this.commonData = reqCommonMsg(this.reqParams)
      exportBizApparchDemandExcel(this.commonData);
    },
    /**
     * 获取业务字典参数
     */
    async getBizDict() {
      let dicData = await this.$params.getBizDict('["demandSource","demandCategory","priorLevel","reviewStatus","demandStatus","labelValues","labelType","demandLabelType"]');
      this.findObject(this.option.column, 'demandSource').dicData = dicData.demandSource;
      this.findObject(this.option.column, 'demandCategory').dicData = dicData.demandCategory;
      this.findObject(this.option.column, 'priorLevel').dicData = dicData.priorLevel;
      this.findObject(this.option.column, 'reviewStatus').dicData = dicData.reviewStatus;
      this.findObject(this.option.column, 'demandStatus').dicData = dicData.demandStatus;

      this.findObject(this.option.column, 'labelInfo').children.column[0].dicData = dicData.labelType;
      this.findObject(this.option.column, 'labelInfo').children.column[1].dicData = dicData.demandLabelType;
      // this.findObject(this.option.column, 'projectId').value = this.projectInfo.id;
      // this.findObject(this.option.column, 'projectName').value = this.projectInfo.projectName;
    },
    /**
     * 调用子组件方法查询历史
     */
    getHistoryRecord () {
      setTimeout(() => {
        this.$refs.historyRecord.getUpdateHistoryRecord(this.form.id);
      })
    },
  },
  created() {
    this.showColumn = this.$getStore({name: this.userInfo.userId+'bizApparchDemandColumn'});
    //获取业务字典
    setTimeout(() => {
      this.getBizDict();
    }, 1000);

    //加载机构
    let getOrgTreeTimer = setInterval(() => {
      if(this.genOrgTree){
        let orgTree = [];
        this.genOrgTree.forEach(element => {
          if(element.orgType == '1'){
            orgTree.push(element);
          }
        });
        this.findObject(this.option.column, 'masterDeptName').dicData = [];
        this.findObject(this.option.column, 'masterDeptName').dicData = this.deepClone(orgTree); 
    
        this.findObject(this.option.column, 'assistDeptName').dicData = [];
        this.findObject(this.option.column, 'assistDeptName').dicData = this.deepClone(orgTree); 
        clearInterval(getOrgTreeTimer);
      }
    }, 100);
  },
  watch: {
    showColumn: {
      handler(newValue, oldValue) {
        this.$setStore({name:  this.userInfo.userId+'bizApparchDemandColumn', content: this.showColumn});
      },
      deep: true
      //this.$setStore({name:  this.userInfo.userId+'bizApparchDemandColumn', content: this.showColumn});
    }
  }
};
</script>
